﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NextCMS.Models;

/// <summary>
/// Summary description for Contents
/// </summary>
namespace Modules
{
    public class Contents : IPageModule
    {
        public string GetLayoutModeHTML(PageModuleModel pmm, ModuleModel mm, int UserLanguageId)
        {
            string url = VirtualPathUtility.ToAbsolute(mm.Settings);

            
            if (pmm.RefId > 0)
            {
                PageContentsHelper pcc = new PageContentsHelper();
                PageContentModel pcm = pcc.GetById(pmm.RefId,UserLanguageId);
                if (pcm != null)
                {
                    url = url + "?Id=" + pmm.RefId + "&PageModuleId=" + pmm.Id + "";
                    return "<div class='Module' onclick='javascript:OpenEditModuleDialog(\"" + mm.Code + "\"," + pcm.Id + "," + pmm.Id + ",\"" + url + "\",$(window).width() - 100,$(window).height() - 100);'>" + pcm.Name + "</div>";
                }
                else
                {
                    url = url + "?Id=0&PageModuleId=" + pmm.Id + "";
                    return "<div class='Module' onclick='javascript:OpenEditModuleDialog(\"" + mm.Code + "\",0," + pmm.Id + ",\"" + url + "\",$(window).width() - 100,$(window).height() - 100);'>Content</div>";
                }
            }
            else
            {
                url = url + "?Id=0&PageModuleId=" + pmm.Id + "";
                return "<div class='Module' onclick='javascript:OpenEditModuleDialog(\"" + mm.Code + "\",0," + pmm.Id + ",\"" + url + "\",$(window).width() - 100,$(window).height() - 100);'>Content</div>";
            }
        }

        public string GetViewModeHTML(PageModuleModel pmm, ModuleModel mm, int UserLanguageId)
        {
            if (pmm.RefId > 0)
            {
                PageContentsHelper pcc = new PageContentsHelper();
                PageContentModel pcm = pcc.GetById(pmm.RefId,UserLanguageId);
                if (pcm != null)
                    return pcm.Content;
                else
                    return "";
            }
            else
            {
                return "";
            }
        }
    }
}